package yf.mall.utils;

import com.yf.response.RRException;
import yf.mall.common.Const;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class CodeUtil {

    public static String getTeam(String code){
        if(code.equals(Const.ADMIN_CODE)){
            return "";
        }
        String regEx = "[a-zA-Z]+";
        Pattern pattern = Pattern.compile(regEx);
        Matcher matcher = pattern.matcher(code);
        if (matcher.find()) {
            return matcher.group(); // you can get it from desired index as well
        } else {
           return null;
        }
    }

    public static String getCodeNumber(String code){
        String regEx = "[0-9]+";
        Pattern pattern = Pattern.compile(regEx);
        Matcher matcher = pattern.matcher(code);
        if (matcher.find()) {
            return matcher.group(); // you can get it from desired index as well
        } else {
            throw new RRException("团队编码不存在");
        }
    }

}
